import service, { useRequest } from "@/path/service"
import { getDefCommon, getDefOrderInfo } from "./defData";
import {
  TypeCommon, TypeIndexInfo, TypeOrderIndex, TypePayIndex, TypeOrderList, TypePayRefund, TypeOrderDetail, TypeOrderScanCode, TypeOrderRecordList
} from "./type"
/*
* 初始化
*/
export function useCommonInit() {
  return useRequest<TypeCommon.parameter, TypeCommon.returnedVal>(`common/init`, { skipToken: true, cacheType: "sessionStorage", init: true }, getDefCommon())
}
/*
* 获取首页列表数据
*/
export function useIndexInfo() {
  return useRequest<TypeIndexInfo.parameter, TypeIndexInfo.returnedVal>(`index/index`, { skipToken: true, init: true }, [])
}

/**下单 */
export function orderIndex(params: TypeOrderIndex.parameter) {
  return service.post<TypeOrderIndex.returnedVal>(`order/index`, { data: params, skipToken: false, loading: true })
}

/**订单列表 */
export function orderList(params: TypeOrderList.parameter) {
  return service.post<TypeOrderList.returnedVal>(`order/list`, { data: params, skipToken: false, loading: false })
}

/*
* 获取首页列表数据
*/
export function useOrderDetail() {
  return useRequest<TypeOrderDetail.parameter, TypeOrderDetail.returnedVal>(`order/info`, { skipToken: false }, getDefOrderInfo())
}
/**订单详情 */
export function orderDetail(params: TypeOrderDetail.parameter) {
  return service.post<TypeOrderDetail.returnedVal>(`order/info`, { data: params, skipToken: false, loading: true })
}

/**微信支付 */
export function payIndex(params: TypePayIndex.parameter) {
  return service.post<TypePayIndex.returnedVal>(`pay/index`, { data: params, skipToken: false, loading: true })
}

/**订单退款 */
export function payRefund(params: TypePayRefund.parameter) {
  return service.post<TypePayRefund.returnedVal>(`pay/refund`, { data: params, skipToken: false, loading: true, closeable: false })
}
/**核销 */
export function orderScanCode(params: TypeOrderScanCode.parameter) {
  return service.post<TypeOrderScanCode.returnedVal>(`order/scanCode`, { data: params, skipToken: false, loading: true, toastType: "dialog" })
}
/**核销记录-核销员 */
export function orderScanRecord(params: TypeOrderRecordList.parameter) {
  return service.post<TypeOrderRecordList.returnedVal>(`order/scanRecord`, { data: params, skipToken: false, loading: true })
}
/**核销记录-用户 */
export function orderRecord(params: TypeOrderRecordList.parameter) {
  return service.post<TypeOrderRecordList.returnedVal>(`order/record`, { data: params, skipToken: false, loading: true })
}